/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * CipherModePaddingSelectorDialog.java
 *
 * Created on 08.09.2008, 14:04:07
 */

package jcrypter.utils;

import java.util.ResourceBundle;
import javax.swing.JFrame;

/**
 *
 * @author uli
 */
public class CipherModePaddingSelectorDialog extends javax.swing.JDialog {

    /** Creates new form CipherModePaddingSelectorDialog */
    public CipherModePaddingSelectorDialog(JFrame parent,
                                            boolean modal,
                                            String[] ciphers,
                                            String[] modes,
                                            String[] paddings)
    {
        super(parent, modal);
        initComponents();
        //Save the parameter arrays to member variables
        this.ciphers = ciphers;
        this.modes = modes;
        this.paddings = paddings;
        //Init combo boxes
        for(String c : ciphers)
        {
            cipherComboBox.addItem(c);
        }
        for(String c : modes)
        {
            modeComboBox.addItem(c);
        }
        for(String c : paddings)
        {
            paddingComboBox.addItem(c);
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        cipherLabel = new javax.swing.JLabel();
        cipherComboBox = new javax.swing.JComboBox();
        modeLabel = new javax.swing.JLabel();
        modeComboBox = new javax.swing.JComboBox();
        okButton = new javax.swing.JButton();
        paddingLabel = new javax.swing.JLabel();
        paddingComboBox = new javax.swing.JComboBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle(i18n.getString("Select_Cipher")); // NOI18N

        cipherLabel.setText(i18n.getString("CipherLabel.text")); // NOI18N

        modeLabel.setText(i18n.getString("ModeLabel.text")); // NOI18N

        okButton.setText(i18n.getString("OK")); // NOI18N
        okButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                okButtonMouseClicked(evt);
            }
        });

        paddingLabel.setText(i18n.getString("PaddingLabel.text")); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(okButton, javax.swing.GroupLayout.PREFERRED_SIZE, 163, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(modeLabel)
                            .addComponent(paddingLabel)
                            .addComponent(cipherLabel))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(cipherComboBox, javax.swing.GroupLayout.Alignment.LEADING, 0, 98, Short.MAX_VALUE)
                            .addComponent(paddingComboBox, javax.swing.GroupLayout.Alignment.LEADING, 0, 98, Short.MAX_VALUE)
                            .addComponent(modeComboBox, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cipherLabel)
                    .addComponent(cipherComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(modeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(modeLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(paddingLabel)
                    .addComponent(paddingComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(okButton)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void okButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_okButtonMouseClicked
        this.setVisible(false);
}//GEN-LAST:event_okButtonMouseClicked

    //Getters
    public String getCipher()
    {
        return (String) cipherComboBox.getSelectedItem();
    }
                                         
    public String getMode()
    {
        return (String) modeComboBox.getSelectedItem();
    }
    
    public String getPadding()
    {
        return (String) paddingComboBox.getSelectedItem() + "Padding";
    }
    
    //Setters
    public void setCipher(String cipher)
    {
        cipherComboBox.setSelectedItem(cipher);
    }
    
    public void setMode(String mode)
    {
        cipherComboBox.setSelectedItem(mode);
    }
    
    public void setPadding(String padding)
    {
        cipherComboBox.setSelectedItem(padding);
    }
    
    
    //Members
    private String[] ciphers;
    private String[] modes;
    private String[] paddings;
    
    //Resource bundles
    ResourceBundle i18n = ResourceBundle.getBundle("jcrypter/utils/Bundle");

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox cipherComboBox;
    private javax.swing.JLabel cipherLabel;
    private javax.swing.JComboBox modeComboBox;
    private javax.swing.JLabel modeLabel;
    private javax.swing.JButton okButton;
    private javax.swing.JComboBox paddingComboBox;
    private javax.swing.JLabel paddingLabel;
    // End of variables declaration//GEN-END:variables

}
